// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;
import objctl = require("../objctl/fishctl");
@ccclass
export default class FishMgr {
    fishGroup: Array<objctl.FishController>;
    
    constructor () {
        console.log("FishMgr constructor()")
        this.fishGroup = new Array<objctl.FishController>()
    }
    
    public GenerateFish(num:number,river:cc.Node,fishPreb:cc.Prefab)
    {
        for (let index = 0; index < num; index++) 
        {
            let obj = cc.instantiate(fishPreb)
            let fc = obj.getComponent(objctl.FishController)
            fc.SetRiver(river)
            this.fishGroup.push(fc)
        }
    }

    public DoUpdate(dt:number){
        this.fishGroup.forEach(function(value:objctl.FishController){
            value.DoUpdate(dt)
        })
    }

    public CatchFish():objctl.FishController{
        let r = Math.round(Math.random() * 100)
        if(r > 70)
        {
            return this.fishGroup.shift()
        }
        return null
    }

    public FishNum():number{
        return this.fishGroup.length
    }
    // update (dt) {}
}
